public class ThreadDemo6 {
    public static void main(String[] args) throws InterruptedException {
        Thread thread  = new Thread(()->{
            System.out.println("这是一个线程!");
            try {
                Thread.sleep(1000);
            } catch (InterruptedException e) {
                e.printStackTrace();
            }
        },"线程一");

        System.out.println("获取线程的ID: " + thread.getId());//获取线程ID
        System.out.println("获取线程名称: " + thread.getName());//获取线程名称
        System.out.println("当前线程状态: " + thread.getState()); //NEW代表线程新建
        System.out.println("当前线程状态: " + thread.isAlive()); //false代表PCD(线程)没有存在
        thread.start();
        System.out.println("当前线程状态: " + thread.getState());//RUNNABLE代表线程还在运行
        System.out.println("当前线程状态: " + thread.isAlive());//true代表PCD(线程)存在
        Thread.sleep(2000);
        System.out.println("当前线程状态: " + thread.getState());//TERMINATED代表线程结束
        System.out.println("当前线程状态: " + thread.isAlive());

    }
}
